package com.funtl.spring.cloud.alibaba.unit.config;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @ClassName GatewayConfig
 * @Description TODO
 * @Author Mr.Starry
 * @Date 2019/12/16 21:53
 * @Version 1.0
 */
@Configuration
public class GatewayConfig {
    @Bean
    @Order(-1)
    public GlobalFilter globalFilter() {
        return new GlobalFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println("全局过滤器1");
                return chain.filter(exchange);
            }
        };
    }

    @Bean
    @Order(-2)
    public GlobalFilter secondGlobalFilter() {
        return new GlobalFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println("全局过滤器2");
                return chain.filter(exchange);
            }
        };
    }
}
